# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//build_tools/bazel:build_defs.oss.bzl", "defaulting_select", "iree_compiler_cc_library")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

exports_files([
    "api_exports.c",
    "api_exports.def",
    "api_exports.ld",
    "api_exports.lst",
])

# IMPORTANT: If modifying the list of dependencies, mirror the changes
# manually into:
#   1. CMakeLists.txt _EXPORT_OBJECT_LIBS
#   2. TODO: Something for bazel.
# The CI will complain if you get it wrong.
iree_compiler_cc_library(
    name = "StaticImpl",
    deps = [
        "//compiler/src/iree/compiler/API/Internal:CompilerDriver",
        "//compiler/src/iree/compiler/API/Internal:IREECodegenDialectCAPI",
        "//compiler/src/iree/compiler/API/Internal:IREECompileToolEntryPoint",
        "//compiler/src/iree/compiler/API/Internal:IREEGPUDialectCAPI",
        "//compiler/src/iree/compiler/API/Internal:IREELinkToolEntryPoint",
        "//compiler/src/iree/compiler/API/Internal:IREEMLIRLSPServerToolEntryPoint",
        "//compiler/src/iree/compiler/API/Internal:IREEOptToolEntryPoint",
        "//compiler/src/iree/compiler/API/Internal:IREEReduceToolEntryPoint",
        "//compiler/src/iree/compiler/API/Internal:LLDToolEntryPoint",
        "//llvm-external-projects/iree-dialects:CAPI",
        "@llvm-project//mlir:CAPIDebug",
        "@llvm-project//mlir:CAPIGPU",
        "@llvm-project//mlir:CAPIIR",
        "@llvm-project//mlir:CAPIInterfaces",
        "@llvm-project//mlir:CAPILLVM",
        "@llvm-project//mlir:CAPILinalg",
        "@llvm-project//mlir:CAPIPDL",
        "@llvm-project//mlir:CAPITarget",
        "@llvm-project//mlir:CAPITransformDialect",
        "@llvm-project//mlir:CAPITransformDialectTransforms",
        "@llvm-project//mlir:CAPITransforms",
        "@llvm-project//mlir:FromLLVMIRTranslation",
    ],
)

iree_compiler_cc_library(
    name = "SharedImpl",
    srcs = [
        "//lib:libIREECompiler.so",
    ],
    tags = ["skip-bazel_to_cmake"],
)

bool_flag(
    name = "link_shared",
    build_setting_default = False,
)

config_setting(
    name = "link_shared_config",
    flag_values = {
        ":link_shared": "True",
    },
)

alias(
    name = "Impl",
    actual = defaulting_select({
        ":link_shared_config": ":SharedImpl",
        "//conditions:default": ":StaticImpl",
    }),
)
